package com.hnevc.androidhomework6;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class DetailActivity extends AppCompatActivity {
    ImageView mIvIcon;
    TextView mTvName,mTvtaste,mTvPrice,mTvContent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        mIvIcon=(ImageView) findViewById(R.id.iv_icon);
        mTvName=(TextView) findViewById(R.id.tv_name1);
        mTvtaste=(TextView) findViewById(R.id.tv_taste1);
        mTvPrice=(TextView) findViewById(R.id.tv_price1);
        mTvContent=(TextView) findViewById(R.id.tv_content);
        //获取传递过来的意图
        Intent intent = getIntent();
        //从意图获取数据
        int position = intent.getIntExtra("position", 0);
        String food_name = intent.getStringExtra("food_name");
        String food_pic = intent.getStringExtra("food_pic");
        String food_desc = intent.getStringExtra("food_desc");
        String food_price = intent.getStringExtra("food_price");
        String food_hot = intent.getStringExtra("food_hot");
        mTvContent.setText(food_desc);
        String price = mTvPrice.getText().toString();
        mTvPrice.setText( food_price+"元");
        mTvName.setText(food_name);
        // mIvIcon.setImageResource(Integer.parseInt(food_pic));

        //根据文件名，获取资源id
        int mipmap = getResources().getIdentifier(food_pic.substring(0, food_pic.indexOf(".")),
                "mipmap", getPackageName());
        mIvIcon.setImageResource(mipmap);
        Toast.makeText(this,""+position,Toast.LENGTH_SHORT).show();

    }
}
